home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / mcu11 / mcx11v15.arc / TEST.AS < prev    next >
Text File  |  1990-12-08  |  12KB  |  321 lines

  1. *TEST.AS
  2. *
  3. *******************************************************************************
  4. *    MCX ESR equates                                                          *
  5. *******************************************************************************
  6.  
  7. .wait.   equ   1                   Wait for an event to occur
  8. .signal. equ   2                   Signal the occurence of an event
  9. .pend.   equ   3                   Set a semaphore to PENDing state
  10. .send.   equ   4                   Send a message to a task
  11. .sendw.  equ   5                   Send a message and wait for response
  12. .receive. equ   6                  Receive a message 
  13. .deque.  equ   7                   Dequeue an entery from a FIFO queue
  14. .enque.  equ   8                   Enqueue an entry into a FIFO queue
  15. .resume. equ   9                   Resume a suspended task
  16. .suspend. equ   10                 Suspend a task
  17. .terminate. equ   11               Terminate a task
  18. .execute. equ   12                 Execute a task
  19. .delay.  equ   13                  Delay a task for a period of time
  20. .timer.  equ   14                  Set up a timer
  21. .purge.  equ   15                  Purge active timer(s)
  22.  
  23. *******************************************************************************
  24. *    MESSAGE EQUATES                                                          *
  25. *******************************************************************************
  26.  
  27. MLINK    equ   0                   Message link pointer
  28. MTASK    equ   2                   Message's sending task
  29. MSEMA    equ   3                   Message semaphore
  30. MBODY    equ   4                   Start of message body
  31.  
  32. *******************************************************************************
  33. *    TEST equates                                                             *
  34. *******************************************************************************
  35.  
  36. * REMEMBER task 1 is the CLOCK DRIVER *
  37.  
  38. T2     equ    2
  39. T3     equ    3
  40. T4     equ    4
  41. T5     equ    5
  42.  
  43. SEMA_a equ    2          Semaphore that T2 waits on
  44. SEMA_b equ    3          Semaphore that T3 waits on
  45. SEMA_C equ    4          Semaphore that is reset by T4
  46. SEMA_D equ    5          Semaphore that is signalled by T4 & waited by T3
  47.  
  48. TESTQ_1 equ    1         Test queue 1, used by T5 & T2
  49. TESTQ_2 equ    2         Test queue 2, used by T4 & T3
  50.  
  51. tstmsg  equ   $0001      Message to be sent to task 4
  52. savptr  equ   $0008
  53. qdestn  equ   $0010      Address of dequeued test text string
  54.  
  55. ENDOFQ  equ   '$         End of queue message is dollar sign ($)
  56. *******************************************************************************
  57.  
  58.         ORG $E800
  59.  
  60. ******************************************************************************
  61. *  Out of reset task 1 and 2 (and of course the null task) are the only tasks
  62. *  that are runnable. This is setup in the SYSTEM.AS file on task
  63. *  initialization. The other 3 tasks are in the idle state.
  64. ******************************************************************************
  65. *task 2 todo's: 
  66. * 1. Delays 5 seconds.                               
  67. *    During this delay we will spend most of our time in the null task.
  68. *    Except for when tick timer expires.
  69. * 2. Make task 3 runnable.
  70. *    This will not cause a task switch due to task 3 is a lower priority.
  71. * 3. Waits on named semaphore (SEMA_a). Upon a signal from task 5.  
  72. * 4. It deques a message sent from task 5. Since task 5 is enqueing to Queue 1
  73. *    (1 x 8) queue and is a lower priority task, we will bounce back in forth
  74. *    between task 2 and 5 until complete message is sent. If Queue 1 would have
  75. *    been configured as a 4 x 2 queue, then task 2 would not have been awaken
  76. *    on the dequeue ESR until all 4 bytes were enqueued by task 5.
  77. * 5. Signal named semaphore (SEMA_b).
  78. * 6. Terminate self.
  79. *****************************************************************************
  80. tsk2    clra
  81.         clrb
  82.         ldx    #5000/49
  83.         swi
  84.          FCB   .delay.    Delay start of task for 5 seconds. Except for
  85. *                          the first time through this code, there should now
  86. *                          be 2 timers in the thread. (see task 5)
  87.     
  88.         ldaa   #T3        set up task 3 for execution
  89.         swi
  90.          FCB   .execute.
  91.  
  92.         ldab   #SEMA_a    wait on semaphore A
  93.         swi
  94.          FCB    .wait.
  95.  
  96. dqloop  ldaa   #TESTQ_1   dequeue from queue 1
  97.         swi
  98.         FCB    .deque.
  99.         cmpa   #ENDOFQ    compare dequeued byte with end-of queue character
  100.         bne    dqloop     loop until a match is found
  101.  
  102.         ldab   #SEMA_b    signal semaphore B
  103.         swi
  104.         FCB    .signal.
  105.  
  106.         clra
  107.         swi               terminate self
  108.         FCB    .terminate.
  109.  
  110. *******************************************************************************
  111. *task 3 todo's:
  112. * 1.  Cause task 5 to become runnable.
  113. *     Task 5 is a lower priority task therefore no task switch.
  114. * 2.  Send a message to task 4 and wait upon the named semaphore (MSEMA).
  115. *     Once MSEMA is signalled.
  116. * 3.  Dequeue from Queue 2 (5 x 1) and put message at location $0010.
  117. *     Compare message to expected message, then wait on named semaphore (SEMA_b)
  118. *     Once SEMA_b is signalled.
  119. * 4.  Resume task 4 from the suspended state.
  120. *     Task 4 is a lower priority therefore no task switch.
  121. * 5.  Suspend task 5 and self.
  122. *     Once allowed to run due to resume ESR from task 4.
  123. * 6.  Pend the named semaphore (SEMA_c) and wait for named semaphore (SEMA_d).
  124. *     Once semaphore SEMA_d is signalled.
  125. * 7.  Terminate task 5 and self.
  126. *******************************************************************************
  127. tsk3    ldaa   #T5        execute task 5
  128.         swi
  129.         FCB    .execute.
  130.  
  131.         ldd    #msgT3
  132.         std    tstmsg+4   set up address of char string on msg body
  133.         ldaa   #T4        send message to task 4
  134.         clrb              use task semaphore
  135.         ldx    #tstmsg
  136.         swi
  137.         FCB    .sendw.
  138.  
  139.         ldaa   #TESTQ_2
  140.         ldx    #qdestn   set up destination address
  141.         swi
  142.         FCB    .deque.
  143.  
  144.         ldaa   #msglen
  145.         ldx    #msgT3
  146.         ldy    #qdestn   set up source & destination addresses
  147. cmploop ldab   0,x
  148.         cmpb   0,y
  149.         bne    failT3
  150.         inx
  151.         iny
  152.         deca
  153.         bne    cmploop
  154.  
  155.         ldab   #SEMA_b    wait for semaphore B
  156.         swi
  157.         FCB    .wait.
  158.  
  159.         ldaa   #T4       set up to resume task 4
  160.         swi
  161.         FCB    .resume.
  162.  
  163.         ldaa   #T5       set up to suspend task 5
  164.         swi
  165.         FCB    .suspend.
  166.  
  167.         clra             set up to suspend self
  168.         swi
  169.         FCB    .suspend.
  170.  
  171.        ldab    #SEMA_C   pend on semaphore C
  172.        swi
  173.        FCB    .pend.
  174.  
  175.        ldab    #SEMA_D   wait on semaphore D
  176.        swi
  177.        FCB    .wait.
  178.  
  179.        ldaa    #T5       terminate task 5
  180.        swi
  181.        FCB    .terminate.
  182.  
  183.        clra              terminate self
  184.        swi
  185.        FCB    .terminate.
  186.  
  187. failT3 stop              halt if matchup fails
  188.  
  189. msgT3  FCC     "ABCDE"
  190. msglen equ     *-msgT3
  191.  
  192. *******************************************************************************
  193. *task 4 todo's:
  194. * 1.  Wait on message from task 3. Strip bytes from message.
  195. * 2.  Enqueue stripped bytes into queue 2.
  196. * 3.  Signal the named semaphore (MSEMA).
  197. *     This will cause a task switch due to task 3 (waiting on MSEMA) is
  198. *     a higher priority task.
  199. * 4.  Purge the timer setup by task 5.
  200. *     Once allowed to run again due to resume from task 3.    
  201. * 6.  Signal named semaphores (SEMA_c) and (SEMA_d) and allow task 3 to run.
  202. *     Since task 3 is a higher priority we will do a task switch.
  203. * 7.  Setup a 10 second timer. Cause task 2 to execute from start.
  204. *     Since task 2 is a higher priority we will do a task switch. 
  205. *     Notice since we are executing task 2, which jumps to start of task 2
  206. *     we are actually starting the whole test over. But item 8. below did not
  207. *     run. However it will run as soon as the delay in task 2 is started.
  208. *     Since no other task is in the run state except task 4. We will run
  209. *     the terminate in item 8, once the delay of task 2 is started, and
  210. *     then go to the null task.
  211. * 8.  Terminate self.
  212. *
  213. ******************************************************************************
  214. tsk4    clra               set up to receive highest priority message
  215.          swi
  216.          FCB    .receive.  receive the message from task 3
  217.  
  218.          stx    savptr     save ptr to message
  219.          ldx    MBODY,x        get address of test text string
  220.          ldaa   #TESTQ_2   enqueue to queue 2
  221.          swi
  222.          FCB    .enque.
  223.  
  224.          ldx    savptr     restore message address
  225.          ldab   MSEMA,x        get semaphore number to signal
  226.          swi
  227.          FCB    .signal.
  228.  
  229.          ldaa   #T5        Purge the 10 second timer set up by
  230.          clrb               task 5 and using the task semaphore.
  231.          ldx    #1
  232.          swi
  233.           FCB   .purge.
  234.  
  235.          clra
  236.          swi
  237.          FCB    .suspend.        suspend self
  238.  
  239.          ldab   #SEMA_C    signal semaphore C
  240.          swi
  241.          FCB    .signal.
  242.  
  243.          ldab   #SEMA_D    signal semaphore D
  244.          swi
  245.          FCB    .signal.
  246.  
  247.          ldaa   #T3        resume task 3
  248.          swi
  249.          FCB    .resume.
  250.  
  251.          clra
  252.          clrb
  253.          ldx    #10000/49  Set up a 10 second timer for self.
  254.          swi               This timer should disappear when the
  255.           FCB   .timer.      task is terminated.
  256.  
  257.          ldaa   #T2        execute task 2
  258.          swi
  259.          FCB    .execute.
  260.  
  261.          clra              terminate task 4 (self)
  262.          swi
  263.          FCB    .terminate.
  264.  
  265. ******************************************************************************
  266.  
  267. *task 5 todo's:
  268. * 1.  Setup a 10 second timer and cause task 4 to be runnable.
  269. * 2.  Signal named semaphore (SEMA_a). Enqueue data to Queue 1.
  270. ******************************************************************************
  271. tsk5     clra
  272.          clrb
  273.          ldx    #10000/49
  274.          swi               Set up a 10 second timer for self. This timer
  275.           FCB   .timer.     will be purged by task 4.
  276.  
  277.          ldaa   #T4        execute task 4
  278.          swi
  279.          FCB    .execute.
  280.  
  281.          ldab   #SEMA_a    signal semaphore a
  282.          swi
  283.          FCB    .signal.
  284.  
  285.          ldy    #lisT5     pointer to list of characters
  286. enqloop  ldx    0,y        get next char from list
  287.          iny
  288.          ldaa   #TESTQ_1   enqueue to queue 1
  289.          swi
  290.          FCB    .enque.
  291.  
  292.          xgdx
  293. ****(V1.4 #1) ****
  294.          cmpa   #ENDOFQ    look for end of queue                          |
  295.          bne    enqloop
  296.          
  297.          stop              should never get here.
  298.  
  299. lisT5    FCC    "ZYX$"
  300.  
  301. *******************************************************************************
  302. *   Now set up the starting addresses in the TCB                              *
  303. *******************************************************************************
  304. * Be sure to download SYSTEM.S19 into the EVM before loading the TEST.S19
  305. * file. This will assure that the starting addresses will be overlayed into
  306. * the task control blocks properly. These addresses are set up to the task 
  307. * number in SYSTEM.AS file and therfore are not runnable.
  308. ******************************************************************************
  309.          ORG  $E014
  310.          FDB  tsk2
  311.  
  312.          ORG  $E01B
  313.          FDB  tsk3
  314.  
  315.          ORG  $E022
  316.          FDB  tsk4
  317.  
  318.          ORG  $E029
  319.          FDB  tsk5
  320.  
  321.